package com.mengchengnet.chaperonage.util;

import android.content.Context;
import android.text.TextUtils;

import java.util.List;

public class ValueUtil {
    public static final String TAG = "ValueUtil";

    public static boolean isEmpty(Object object) {
        return null == object;
    }

    public static int dp2px(Context context, float dp) {
        final float scale = context.getResources().getDisplayMetrics().density;
        return (int) (dp * scale + 0.5f);
    }

    public static boolean isStrEmpty(String value) {
        if (null == value || "".equals(value.trim()) || "null".equals(value)) {
            return true;
        } else {
            // 判断是否全是全角空格
            value = value.replaceAll(" ", "").trim();
            if (null == value || "".equals(value.trim())) {
                return true;
            }
        }
        return false;
    }
    public static boolean isStrNotEmpty(String value) {
        if (null == value || "".equals(value.trim())) {
            return false;
        } else {
            // 判断是否全是全角空格
            value = value.replaceAll(" ", "").trim();
            if (null == value || "".equals(value.trim())) {
                return false;
            }
        }
        return true;
    }
    public static boolean isNotEmpty(Object object) {
        return null != object;
    }
    /**
     * 因为服务器给的坐标是整数,需要转换为浮点数
     */
    public static double formatCoord(String optString) {
        if (isStrEmpty(optString)) {
            return 0;
        }
        double result = Double.parseDouble(optString);

        return result;
    }
    public static boolean isListNotEmpty(List<?> noteList) {
        return null != noteList && noteList.size() > 0;
    }

    public static boolean isListEmpty(List<?> noteList) {
        return null == noteList || noteList.size() == 0;
    }

    public static boolean isMobileNO(String mobile){
        String telRegex = "[1][34578]\\d{9}";
        if (TextUtils.isEmpty(mobile)){
            return false;
        }else return mobile.matches(telRegex);
    }
}
